package Strategy;

import Observer.EnvironmentData;
import java.util.ArrayList;
import java.util.List;

/**
 * 标准路径规划策略 - 适用于单个农机的常规作业
 */
public class StandardPathPlanning implements PathPlanningStrategy {

    private EnvironmentData environmentData;

    public StandardPathPlanning(EnvironmentData data) {
        this.environmentData = data;
    }

    @Override
    public Path calculatePath(FieldMap map, EnvironmentData data) {
        // 基础路径规划逻辑 - 按行扫描方式
        List<Coordinate> waypoints = new ArrayList<>();
        double fieldWidth = map.getWidth();
        double fieldHeight = map.getHeight();
        double machineWidth = 3.0; // 农机作业宽度
        double spacing = machineWidth * 0.9; // 行距，留10%重叠

        // 生成蛇形路径（来回扫描）
        for (double y = 0; y < fieldHeight; y += spacing) {
            // 奇数行从左到右，偶数行从右到左
            if ((int)(y/spacing) % 2 == 0) {
                waypoints.add(new Coordinate(0, y));
                waypoints.add(new Coordinate(fieldWidth, y));
            } else {
                waypoints.add(new Coordinate(fieldWidth, y));
                waypoints.add(new Coordinate(0, y));
            }
        }

        return new Path(waypoints, "Standard Path");
    }

}